public class Leet474 {
    public static void main(String[] args) {
        System.out.println(findMaxForm(new String[]{"0", "1"},1,1));
    }
    static public int findMaxForm(String[] strs, int m, int n) {
        int[][][] dp = new int[strs.length+1][m+1][n+1];
        for (int i = 1; i <= strs.length; i++) {
            int o = 0;
            int l = 0;
            for (int j = 0; j < strs[i-1].length(); j++) {
                if (strs[i-1].charAt(j)=='0')
                    o++;
                else
                    l++;
            }
            for (int j = 0; j <=m ; j++) {
                for (int k = 0; k <=n ; k++) {
                    dp[i][j][k]=dp[i-1][j][k];
                    if (j>=o&&k>=l)
                        dp[i][j][k]=Math.max(dp[i-1][j][k],dp[i-1][j-o][k-l]+1);
                }
            }
        }
        return dp[strs.length][m][n];
    }
}
